# -*- coding:utf-8 -*-
"""
=============================
this is a feibot product,
all rights reserved.
www.feibot.com
@author: Gu Tianyuan
@email: g@feibot.com
@time: ${DATE}:${TIME}
@product: ${PRODUCT_NAME}
=============================
"""
from multiprocessing import Process

import platform4
import gtyTools.tools
import os


def runlinuxbash():
    # 替换启动脚本
    os.system('cp /home/feibot/platform/shellScripts/start.sh /home/feibot/')
    # 复制vnc，anydesk，与更新panel脚本
    os.system('cp /home/feibot/platform/shellScripts/autostartvnc.sh /home/feibot/cmds/')
    os.system('cp /home/feibot/platform/shellScripts/add_anydesk_to_panel.sh /home/feibot/cmds/')
    os.system('cp /home/feibot/platform/shellScripts/installandesk.sh /home/feibot/cmds/')
    os.system('cp /home/feibot/platform/shellScripts/xfce4-panel.xml /home/feibot/cmds/')
    # 启动vnc，更新xface4-panel面板
    os.system('bash /home/feibot/cmds/add_anydesk_to_panel.sh')
    os.system('bash /home/feibot/cmds/autostartvnc.sh')
    # 复制升级脚本与UI到/home/feibot/subModules/update_sw下
    os.system('cp -R /home/feibot/platform/subModules/update_sw /home/feibot/')
    #从cmds下复制备份到update_sw下
    os.system('mv /home/feibot/cmds/update_sw_dev.sh /home/feibot/cmds/update_sw_dev_back.sh')
    os.system('cp /home/feibot/platform/subModules/update_sw/update_sw_dev.sh /home/feibot/cmds/')
    os.system('mv /home/feibot/cmds/update_sw_master.sh /home/feibot/cmds/update_sw_master_back.sh')
    #将现有的升级脚本替换到cmds下
    os.system('cp /home/feibot/platform/subModules/update_sw/update_sw_master.sh /home/feibot/cmds/')
    os.system('cp /home/feibot/platform/subModules/update_sw/update_sw_dev.sh /home/feibot/cmds/')
    os.system('touch /home/feibot/Newevent.ini')

if __name__ == '__main__':
    # 检查是否重复运行
    num = gtyTools.tools.checkAlreadyRun()
    if num > 4:
        print("feibot desktop already running!", num)
        exit()
    runlinuxbash()
    # 程序启动
    p = platform4.platForm()
    p.start()
